package org.hawk.gwtppc.webtest.tests.fieldsuite;

import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;

import org.hawk.gwtppc.webtest.common.Asserts;
import org.hawk.gwtppc.webtest.common.Test;
import org.hawk.gwtppc.webtest.tests.mock.ClassMock;
import org.hawk.gwtppc.webtest.tests.mock.EnumMock;
import org.hawk.gwtppc.webtest.tests.mock.GenericClassMock;
import org.hawk.gwtppc.webtest.tests.mock.SubClassMock1;

public class GetGenericTypeTest implements Test {

	public void run() throws Throwable {
		Asserts.assertEquals(SubClassMock1.class.getDeclaredField("serialVersionUID").getGenericType(), long.class);
		Asserts.assertEquals(SubClassMock1.class.getDeclaredField("staticString").getGenericType(), String.class);
		Asserts.assertEquals(SubClassMock1.class.getDeclaredField("parent").getGenericType(), ClassMock.class);
		Asserts.assertEquals(SubClassMock1.class.getDeclaredField("flag").getGenericType(), boolean.class);
		Asserts.assertEquals(EnumMock.class.getField("ALPHA").getGenericType(), EnumMock.class);
		
		Type type = GenericClassMock.class.getDeclaredField("genericField").getGenericType();
		Asserts.assertTrue(type instanceof TypeVariable);
		TypeVariable<?> var = (TypeVariable<?>)type;
		Asserts.assertEquals(var.getName(), "X2");
		Asserts.assertEquals(var.getGenericDeclaration(), GenericClassMock.class);
	}

	public String getName() {
		return "getGenericType()";
	}

}
